// formItemMap.acptStaffIdDepart: 组织机构;
// formItemMap.workGrp：工作组



import _ from "lodash";
import { renameTreeField } from "@utils/dataStruct";

import { getNearMonthDate, getThisMonthDate, getToday } from "./time";
import {
    mobileRule,
    cardNumberRule,
    plateNumberRule,
    idCardRule
} from "@utils/validator";
import { srDictKeyMap } from "@constants/dict";
import { RELEASE_RESULT } from "@constants";
import service from "@service";
import { getTokenInfo, setSessionCookie } from "@utils/session";

import {
    groupCascaderFormRender,
    workTyeCascaderFormConfig,
    workGroupCascaderFormConfig,
    getStaffFormItemRender,
    getIVRFormItemRender,
    checkStaffFormItemRender,
    examinationPlanFormItemRender,
	examinationTemplateFormItemRender,
    selectSamOrgaTreeForCombotree,
    causeOfComplaintFormConfig,
    tissueTreeFormRender
} from "./formRender";
let { today, prevMonth, halfYearAgo, threeMonthsAgo } = getNearMonthDate();

export const formItemMap = {
    /* 入口处理编号 */
    entryNm: (label, key = "key1") => {
        return { key, label };
    },
    /* 卡号 */
    cardNo(label, key, config) {
        label = label || "卡号";
        key = key || "cardNo";
        let itemConfig = {
            key,
            label,
            rules: [cardNumberRule()],
            attrs: {
                maxlength: 16,
                "show-word-limit": true,
            },
            ...config,
        };

        return itemConfig;
    },
    /* 电话 */
    mobile(label, key, config) {
        label = label || "电话";
        key = key || "mobile";
        let itemConfig = {
            key,
            label,
            rules: [mobileRule()],
            ...config,
        };

        return itemConfig;
    },
    /* 车牌号码 */
    vehiclePlate(label, key, config) {
        label = label || "车牌号码";
        key = key || "vehiclePlate";
        let itemConfig = {
            key,
            label,
            rules: [plateNumberRule()],
            ...config,
        };
        return itemConfig;
    },
    /* 证件号码 */
    idCode(label, key, config) {
        label = label || "证件号码";
        key = key || "idCode";
        let itemConfig = {
            key,
            label,
            rules: [idCardRule()],
            ...config,
        };
        return itemConfig;
    },
    /* 起始时间 */
    startAndEndDate: (label, key = "startAndEndDate", config = {}) => {
        let itemConfig = {
            key: key || "startAndEndDate",
            label: label || "起始时间",
            col: 2,
            type: "daterange",
            keyRange: ["startTime", "endTime"],
            ...config,
        };
        if (config.default) {
            if (config.complaintId) {
                itemConfig.default = null;
            } else if (config.default === "month") {
                itemConfig.default = [prevMonth, today];
            } else if (config.default === "threeMonthsAgo") {
                itemConfig.default = [threeMonthsAgo, today];
            }else if (config.default === "thisMonth") {
                let { today, prevMonth } = getThisMonthDate();
                itemConfig.default = [prevMonth, today];
            }else if(config.default === 'today') {
                itemConfig.default = getToday()
            }
        }
        return itemConfig;
    },
    // 获取省市区联动
    getArea({ province = {}, city = {}, area = {} } = {}) {
        const { key: provinceKey } = province;
        const { key: cityKey } = city;
        const { key: areaKey } = area;
        const list = [];
        if (!province.hide) {
            list.push(
                formItemMap.province.apply(this, [
                    province.label,
                    province.key,
                    province,
                ])
            );
        }
        if (city && !city.hide) {
            list.push({
                ...(city || {}),
                label: city.label,
                key: cityKey,
                type: "select",
                dependon: [provinceKey],
                options: (data) => {
                    if (!data || !data[provinceKey]) {
                        return [];
                    }
                    let provinceCode = data[provinceKey];
                    if (!provinceCode) {
                        return [];
                    }
                    return this.$getSrDict(
                        `${srDictKeyMap.city}_${provinceCode}`
                    );
                },
            });
        }
        if (area && !area.hide) {
            list.push({
                ...(area || {}),
                label: area.label,
                key: areaKey,
                type: "select",
                dependon: [cityKey],
                options: (data) => {
                    if (!data || !data[cityKey]) {
                        return [];
                    }
                    let cityCode = data[cityKey];
                    if (!cityCode) {
                        return [];
                    }
                    return this.$getSrDict(
                        `${srDictKeyMap.district}_${cityCode}`
                    );
                },
            });
        }
        return list;
    },
    province(label, key, config) {
        let itemConfig = {
            key: key || "province",
            label: label || "省份",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.province),
            ...(config || {}),
        };
        return itemConfig;
    },

    /* 起始时间 */
    resetDate: (label, key = "startAndEndDate", config = {}) => {
        let itemConfig = {
            key: key || "startAndEndDate",
            label: label || "起始时间",
            col: 2,
            type: "daterange",
            keyRange: ["deptCreateStartTime", "deptCreateEndTime"],
            ...config,
        };
        if (config.default) {
            if (config.complaintId) {
                itemConfig.default = null;
            } else if (config.default === "month") {
                itemConfig.default = [prevMonth, today];
            }
        }
        return itemConfig;
    },
    /* 生效标记 */
    validFlag(label, key, config) {
        let itemConfig = {
            key: key || "validFlag",
            label: label || "生效标记",
            type: "select",
            options: [
                { value: 0, label: "失效" },
                { value: 1, label: "生效" },
            ],
            ...config,
        };
        return itemConfig;
    },
    /* 模板类型 */
    tplType(label, key, config) {
        let itemConfig = {
            key: key || "tplType",
            label: label || "模板类型",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.TMPLT_TYPE_CD),
            ...config,
        };
        return itemConfig;
    },

    /* 证件类型 */
    idType(label, key, config) {
        let itemConfig = {
            key: key || "idType",
            label: label || "证件类型",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.id_card_type),
            ...config,
        };
        return itemConfig;
    },
    /* 支付方式 */
    payMethod(label, key, config) {
        let itemConfig = {
            key: key || "payMethod",
            label: label || "支付方式",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.payMethod),
            ...config,
        };
        return itemConfig;
    },
    /* 退款方式 */
    refundMethod(label, key, config) {
        let itemConfig = {
            key: key || "refundMethod",
            label: label || "退款方式",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.refundMethod),
            ...config,
        };
        return itemConfig;
    },
    /* 发卡方 */
    cardIssuer(label, key, config) {
        let itemConfig = {
            key: key || "cardIssuer",
            label: label || "发卡方",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.CARD_ISSUER),
            ...config,
        };
        return itemConfig;
    },
    /* 回复时限 */
    replyTimeLimit(label, key, config) {
        let itemConfig = {
            key: key || "replyTimeLimit",
            label: label || "回复时限",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.REPLY_LIMIT),
            ...config,
        };
        return itemConfig;
    },
    /* 异常省份 */
    province(label, key, config) {
        let itemConfig = {
            key: key || "province",
            label: label || "异常省份",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.abnormal_prov),
            ...config,
        };
        return itemConfig;
    },
    // 使用场景 - 工作组关联配置
    useType(label, key, config) {
        let itemConfig = {
            key: key || "useType",
            label: label || "使用场景",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.PREREVIEW_TYPE),
            // options: async () => {
            //     return Object.values(SR_SCENE)
            // },
            ...config,
        };
        return itemConfig;
    },
    /* 工单状态 */
    wrkfmStsCd(label, key, config) {
        let itemConfig = {
            key: key || "wrkfmStsCd",
            label: label || "工单状态",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.workOrderStatus),
            ...config,
        };
        return itemConfig;
    },
    /* 退费状态 */
    refundStsCd(label, key, config) {
        let itemConfig = {
            key: key || "refundStatus",
            label: label || "退费状态",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.refund_status),
            ...config,
        };
        return itemConfig;
    },
    /* 受理渠道 */
    acptChnlId(label, key, config) {
        let itemConfig = {
            key: key || "acptChnlId",
            label: label || "受理渠道",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.acptChannel),
            ...config,
        };
        return itemConfig;
    },
    /* 客户类型 */
    custType(label, key, config) {
        let itemConfig = {
            key: key || "custType",
            label: label || "客户类型",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.CUSTOMER_TYPE),
            ...config,
        };
        return itemConfig;
    },
    // 时限状态
    tlmtStsCd(label, key, config) {
        let itemConfig = {
            key: key || "tlmtStsCd",
            label: label || "时限状态",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.TMLMT_STATE_NO),
            ...config,
        };
        return itemConfig;
    },
    // 时限类型
    timeConfType(label, key, config) {
        let itemConfig = {
            key: key || "confType",
            label: label || "时限类型",
            type: "select",
            options: [
                { value: "1", label: "整体" },
                { value: "2", label: "环节" },
            ],
            ...config,
        };
        return itemConfig;
    },
    /* 资料类型 */
    updateDataType(label, key, config) {
        let itemConfig = {
            key: key || "updateDataType",
            label: label || "资料类型",
            // type: 'select',
            options: [{ value: "0", label: "身份证" }],
            ...config,
        };
        return itemConfig;
    },
    /* 补传状态 */
    updateData(label, key, config) {
        let itemConfig = {
            key: key || "isUpdateData",
            label: label || "补传状态",
            type: "select",
            options: [
                { value: 1, label: "待上传" },
                { value: 0, label: "已上传" },
            ],
            ...config,
        };
        return itemConfig;
    },
    /* 投诉渠道 */
    complainantChannel(label, key, config) {
        let itemConfig = {
            key: key || "complainantChannel",
            label: label || "投诉渠道",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.acptChannel),
            ...config,
        };
        return itemConfig;
    },
    /* 车牌颜色 */
    vehicleColor(label, key, config) {
        let itemConfig = {
            key: key || "vehicleColor",
            label: label || "车牌颜色",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.vehicleColor),
            ...config,
        };
        return itemConfig;
    },
    // todo 接口未定
    /* 出站口 */
    exportName(label, key, config) {
        let itemConfig = {
            key: key || "exportName",
            label: label || "出站口",
            type: "select",
            options: [{ value: "1", label: "出站口一" }],
            ...config,
        };
        return itemConfig;
    },
    /* 车辆类型 */
    carType(label, key, config) {
        let itemConfig = {
            key: key || "carType",
            label: label || "车辆类型",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.car_type),
            ...config,
        };
        return itemConfig;
    },
    /* 紧急程度 */
    emergencyLevel(label, key, config) {
        let itemConfig = {
            key: key || "emergencyLevel",
            label: label || "紧急程度",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.urgent),
            ...config,
        };
        return itemConfig;
    },
    /* 树形工作组 （多选按钮）*/
    workGrp(label, key, config = {}, { initInputKey } = {}) {
        label = label || "工作组";
        key = key || "workGrp";

        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            render: this.$getOnceItem(key, () =>
                // 表单数据： 叶子节点 id 数组  ['234', '9843']
                groupCascaderFormRender.apply(this, [
                    {
                        componentsType: "treeSelect",
                        filterTable: false,
                        cascaderProps: {
                            multiple: false,
                            checkStrictly: true,
                        },
                    },
                    {
                        treeMapKey: key + "TreeMap",
                        initInputKey: initInputKey || "",
                    },
                ])
            ),

            ...config,
        };
        return itemConfig;
    },
    /* 员工 */
    staff(label, key, config = {}, renderItemConfig = {}) {
        label = label || "员工";
        key = key || "staff";

        // _.merge({}, itemConfig, config)
        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            // 表单数据：单选：员工对象，或多选：员工对象数组
            render: this.$getOnceItem(key, () =>
                getStaffFormItemRender(
                    _.merge(
                        {},
                        {
                            staffSelectConfig: {
                                hidenGroup: true,
                                autoLoad: true,
                                params: {},
                                isMultiple: false,
                            },
                        },
                        renderItemConfig
                    )
                )
            ),

            ...config,
        };
        return itemConfig;
    },
    /* 投诉主题 */
    srvReqstTypeId(label, key, config = {}) {
        let itemConfig = {
            key: key || "srvReqstTypeId",
            label: label || "投诉主题",
            props: {
                props: {
                    checkStrictly: false,
                    emitPath: false,
                    multiple: false,
                },
            },
        };
        let lastConfig = _.merge({}, itemConfig, config);
        return workTyeCascaderFormConfig.apply(this, [lastConfig]);
    },
     /* 投诉原因 */
     causeOfComplaint(label, key, config = {}) {
        let itemConfig = {
            key: key || "causeOfComplaint",
            label: label || "投诉原因",
            props: {
                props: {
                    checkStrictly: false,
                    emitPath: false,
                    multiple: false,
                },
            },
        };
        let lastConfig = _.merge({}, itemConfig, config);
        return causeOfComplaintFormConfig.apply(this, [lastConfig]);
    },
    // 组织机构,处理部门
    acptStaffIdDepart(label, key, config = {}, serviceConfig = {}) {
        let itemConfig = {
            key: key || "acptStaffIdDepart",
            label: label || "处理部门",
            props: {
                size: "mini",
                "collapse-tags": true,
                "show-all-levels": false,
                props: {
                    checkStrictly: false,
                    emitPath: false,
                    multiple: false,
                },
            },
        };
        const tokenInfo = getTokenInfo() || {};
        let lastConfig = _.merge({}, itemConfig, config);
        let lastServiceConfig = _.merge(
            {},
            {
                cache: false,
                dataIsFlat: false,
                params: {
                    access_token: tokenInfo.access_token,
                    staffId: this.staffId,
                    tenantId: this.tenantId,
                },
            },
            serviceConfig
        );

        return selectSamOrgaTreeForCombotree.apply(this, [lastConfig, lastServiceConfig]);
    },
    // 获取当前员工所配置的角色关联的组织结构
    getOrgByRoleRelate(...reset) {
        let [label, key, config = {}, serviceConfig = {}] = reset;
        const range = this.$roleRelationOrgList; // main.js 中的角色关联的组织

        serviceConfig.optionsGetHandle = (data, dataMap) => {
            const tree = renameTreeField(data, {
                childrenName: "children",
                retainOther: true,
                nameMap: {
                    id: value => ({
                        key: {
                            id: value,
                            disabled: (range||[]).every(v => v.orgId != value)
                        }
                    })
                },
            });
            return tree;
        }

        return formItemMap.acptStaffIdDepart.apply(this, [
            label,
            key,
            config,
            serviceConfig
        ]);
    },
    // 工作组，支持查询全部工作组或者某员工的工作组
    workGroup(label, key, config = {}, serviceConfig = {}) {
        let itemConfig = {
            key: key || "workGrp",
            label: label || "工作组",
            props: {
                size: "mini",
                "collapse-tags": true,
                "show-all-levels": false,
                props: {
                    checkStrictly: true,
                    emitPath: false,
                    multiple: false,
                },
            },
        };
        const tokenInfo = getTokenInfo() || {};
        let lastConfig = _.merge({}, itemConfig, config);
        let lastServiceConfig = _.merge(
            {},
            {
                cache: false,
                dataIsFlat: false,
                params: {
                    access_token: tokenInfo.access_token,
                    staffId: this.staffId,
                    tenantId: this.tenantId,
                },
            },
            serviceConfig
        );

        return workGroupCascaderFormConfig.apply(this, [lastConfig, lastServiceConfig]);
    },
    // 获取用户信息输入框
    getUserInfoInput(label, key, config = {}, serviceConfig = {}) {
        // console.log(label)
        // console.log(key)
        // console.log(config)
        // console.log(serviceConfig)

        let isSelectInput = serviceConfig.type === "selectInput";
        let fromVm = null;

        let optionList = [];

        let selectValueName = _.get(config, "slotRender.prepend.key");
        let optionsConfig = _.get(config, "slotRender.prepend.options");

        if (isSelectInput) {
            if (!serviceConfig.selectIdName) {
                console.warn("selectIdName，为下拉搜索必备字段");
            }
            if (!selectValueName || !optionsConfig) {
                console.warn(
                    "config.slotRender.prepend.key 和 config.slotRender.prepend.options 为下拉搜索必穿字段"
                );
            }
        }

        if (isSelectInput && optionsConfig) {
            if (typeof optionsConfig === "function") {
                optionsConfig().then((res) => {
                    optionList = res;
                    fromVm && fromVm.$forceUpdate();
                });
            } else {
                optionList = optionsConfig;
            }
        }

        let itemConfig = {
            key: key,
            label: label,
            type: "input",
            placeholder: "请输入" + label,
            required: config.required || false,
            slotRender: {
                suffix: {
                    slotName: "suffix",
                    render: (h, { data: { vm, configItem } }) => {
                        //点击icon事件

                        const customerClick = async () => {
                            if (config.userPermission) return;
                            let value = vm.formData[configItem.key];

                            //console.log(vm.formData.cardflag,'======')
                            // console.log(configItem,'====')
                            let selectValue = "";
                            if (isSelectInput) {
                                selectValue = vm.formData[selectValueName];
                            }

                            if (!value || value === 0) {
                                return;
                            }

                            let params = {
                                [serviceConfig.inputIdName]: value,
                                ...serviceConfig.params,
                            };

                            if (isSelectInput) {
                                params[serviceConfig.selectIdName] = selectValue;
                            }

                            if (vm.formData.cardIssuer != "") {
                                let cardIssuer = vm.formData.cardIssuer;
                                let str = cardIssuer.substring(0, 2);
                                if (cardIssuer.length < 4) {
                                    this.$message({
                                        message: "请输入4位编码！",
                                        type: "warning",
                                    });
                                    return;
                                }
                                if (str != "44") {
                                    this.$message({
                                        message: "外省卡无法查询客户信息！",
                                        type: "warning",
                                    });
                                    return;
                                }
                            }
                            let result = await service("queryCustormerInfo", {
                                data: params,
                            });
                            if (result && serviceConfig.callback) {
                                serviceConfig.callback.call(this, result);
                            }
                        };
                        return (
                            <i
                                style={{
                                    cursor: config.userPermission ? "not-allowed" : "pointer",
                                }}
                                class="el-input__icon el-icon-search cursor-pointer"
                                on-click={customerClick}
                            ></i>
                        );
                    },
                },
                prepend: isSelectInput
                    ? {
                          slotName: "prepend",
                          render: (h, { data: { vm, configItem } }) => {
                              fromVm = vm;
                              const handleSelect = (value) => {
                                  vm.formData[selectValueName] = value;
                                  //因为formdata赋值方式不能刷新表单组件 所以又加了个setFormData
                                  vm.setFormData({ selectValueName: value });
                                  config?.slotRender?.prepend?.on?.change &&
                                      config.slotRender.prepend.on.change(value);
                              };
                              return (
                                  <el-select
                                      style="width: 100px;"
                                      placeholder={_.get(config, "slotRender.prepend.label")}
                                      value={vm.formData[selectValueName]}
                                      on-change={handleSelect}
                                  >
                                      {(optionList || []).map((item) => {
                                          return (
                                              <el-option
                                                  key={item.value}
                                                  label={item.label}
                                                  value={item.value}
                                              ></el-option>
                                          );
                                      })}
                                  </el-select>
                              );
                          },
                      }
                    : null,
            },
        };
        let lastConfig = _.merge({}, itemConfig, config);
        return lastConfig;
    },
    /* 申请归档原因 */
    filingReason(label, key, config) {
        let itemConfig = {
            key: key || "filingReason",
            label: label || "申请归档原因",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.FILING_REASON),
            ...config,
        };
        return itemConfig;
    },
     /* 平台类型 */
     platformType(label, key, config) {
        let itemConfig = {
            key: key || "platformType",
            label: label || "平台类型",
            type: "select",
            options: () => this.$getSrDict(srDictKeyMap.PLATFORM_TYPE),
            ...config,
        };
        return itemConfig;
    },
    /* 组织机构 */
    tissueGroup(label, key, config = {}, { initInputKey } = {}) {
        label = label || "组织机构";
        key = key || "orgName";
        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            render: this.$getOnceItem(key, () =>
                tissueTreeFormRender.apply(this, [
                    {
                        componentsType: "treeSelect",
                        filterTable: false,
                        cascaderProps: {
                            multiple: false,
                            checkStrictly: true,
                            label: "name",
                        },
                    },
                    {
                        treeMapKey: key + "TreeMap",
                        initInputKey: initInputKey || "",
                    },
                ])
            ),
            ...config,
        };
        return itemConfig;
    },
    sleepStatus(label, key, config) {
        let itemConfig = {
            key: key || "isSleep",
            label: label || "休眠激活状态",
            type: "select",
            options: [
                { key: "0", label: "激活" },
                { key: "1", label: "休眠" },
            ],
            ...config,
        };
        return itemConfig;
    },
    /* ----------------以上为sr使用------------------ */

    getIVR(label, key, config = {}, renderItemConfig = {}) {
        label = label || "IVR";
        key = key || "IVR";

        // _.merge({}, itemConfig, config)
        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            render: this.$getOnceItem(key, () =>
                getIVRFormItemRender(
                    _.merge(
                        {},
                        {
                            selectConfig: {
                                hidenGroup: true,
                                autoLoad: true,
                                params: {},
                                isMultiple: false,
                            },
                        },
                        renderItemConfig
                    )
                )
            ),

            ...config,
        };
        return itemConfig;
    },
    checkStaffId(label, key, config = {}, renderItemConfig = {}) {
        label = label || "员工选择";
        key = key || "checkStaffId";

        // _.merge({}, itemConfig, config)
        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            render: this.$getOnceItem(key, () =>
                checkStaffFormItemRender(
                    _.merge(
                        {},
                        {
                            selectConfig: {
                                hidenGroup: true,
                                autoLoad: true,
                                params: {},
                                isMultiple: false,
                                services:config.services||''
                            },
                        },
                        renderItemConfig
                    )
                )
            ),

            ...config,
        };
        return itemConfig;
    },
    examinationPlan(label, key, config = {}, renderItemConfig = {}) {
        label = label || "考评计划";
        key = key || "planId";

        // _.merge({}, itemConfig, config)
        let itemConfig = {
            label: label,
            key: key,
            type: "render",
            render: this.$getOnceItem(key, () =>
                examinationPlanFormItemRender(
                    _.merge(
                        {},
                        {
                            selectConfig: {
                                hidenGroup: true,
                                autoLoad: true,
                                params: {},
                                isMultiple: false,
                            },
                        },
                        renderItemConfig
                    )
                )
            ),

            ...config,
        };
        return itemConfig;
    },
		examinationTemplate(label, key, config = {}, renderItemConfig = {}) {
			label = label || "考评模板";
			key = key || "templateId";

			// _.merge({}, itemConfig, config)
			let itemConfig = {
					label: label,
					key: key,
					type: "render",
					render: this.$getOnceItem(key, () =>
					examinationTemplateFormItemRender(
									_.merge(
											{},
											{
													selectConfig: {
															hidenGroup: true,
															autoLoad: true,
															params: config.params || {},
															isMultiple: false,
													},
											},
											renderItemConfig
									)
							)
					),

					...config,
			};
			return itemConfig;
	},
    planTypeq(label, key, config) {
        let itemConfig = {
            key: key || "planTypeq",
            label: label || "计划类型",
            type: "select",
            options: async () => {
                const params = {
                    start: 0,
                    pageNum: 0,
                    params: {
                        tenantId: g_instance.tenantKey,
                        paramsTypeId: "PLAN_TYPE",
                    },
                };
                let res = await service("aiqm_selectByParams", { params });
                if (!res) return;
                const arr = (res?.list || []).map((v) => {
                    return { label: v.paramsName, value: v.paramsPurposeId };
                });
                return arr;
            },
            ...config,
        };
        return itemConfig;
    },
    checkStatus(label, key, config, callback) {
        let itemConfig = {
            key: key || "resultStatus",
            label: label || "质检状态",
            type: "select",
            options: RELEASE_RESULT,
            ...config,
        };
        return itemConfig;
    },
    score(label, key, config) {
        let itemConfig = {
            key: key || "score",
            label: label || "质检评分",
            type: "render",
            render: (h, vm, configItem, data, handle) => {
                const minKey = config?.keyRange[0] || "min";
                const maxKey = config?.keyRange[1] || "max";
                const minValue = data?.[minKey] || "";
                const maxValue = data?.[maxKey] || "";
                const minChangeHandle = (v) => {
                    v = config.trim ? (v || "").trim() : v;
                    handle({
                        [minKey]: v,
                        [maxKey]: maxValue,
                    });
                };
                const maxChangeHandle = (v) => {
                    v = config.trim ? (v || "").trim() : v;
                    handle({
                        [minKey]: minValue,
                        [maxKey]: v,
                    });
                };
                return (
                    <div class="d-flex">
                        <el-input value={minValue} on-input={minChangeHandle} />
                        <span style="margin: 0 5px">—</span>
                        <el-input value={maxValue} on-input={maxChangeHandle} />
                    </div>
                );
            },
            ...config,
        };
        return itemConfig;
    },
    /* 质检页面监听类型 */
    getMonitorType(label, key, config) {
        let itemConfig = {
            key: key || "plamonitorTypenTypeq",
            label: label || "监听类型",
            type: "select",
            options: async () => {
                const params = {
                    start: 0,
                    pageNum: 0,
                    params: {
                        tenantId: g_instance.tenantKey,
                        paramsTypeId: "MONITOR_TYPE",
                    },
                };
                let res = await service("aiqm_selectByParams", { params });
                if (!res) return;
                console.log(res);
                const arr = (res?.list || []).map((v) => {
                    return { label: v.paramsName, value: v.paramsCode };
                });
                return arr;
            },
            ...config,
        };
        return itemConfig;
    },
};
